import { createI18n } from 'vue-i18n'
import zhCN from './lang/zh-CN'
import enUS from './lang/en-US'

const languageList = ['zh-CN', 'en-US']
const customLanguage = localStorage.getItem('APP_LANGUAGE')
const locale = customLanguage && languageList.includes(customLanguage) ? customLanguage : ['zh-CN', 'zh-HK', 'zh-MO', 'zh-TW'].includes(navigator.language) ? 'zh-CN' : 'en-US'
console.log(locale)

const i18n = createI18n({
  legacy: false, // 关键：禁用 legacy 模式，启用组合式 API 支持
  locale: locale.replace('-', '_'),
  messages: {
    zh_CN: {
      ...zhCN
    },
    en_US: {
      ...enUS
    }
  }
})

export default i18n
